package com.orange.agent.todayNews.convert;

import cn.hutool.core.bean.BeanUtil;
import com.orange.agent.todayNews.request.NowNewsApiReq;
import com.orange.agent.todayNews.response.NowNewsApiRes;
import com.orange.bean.todayNews.dto.request.NowNewsReq;
import com.orange.bean.todayNews.dto.response.NowNewsDto;
import com.orange.bean.todayNews.dto.response.NowNewsRes;
import com.orange.framework.consumer.convert.ConsumerConverter;
import org.mapstruct.Mapper;

import java.util.List;

/**
 * TODO
 *
 * @Author YWF
 * @Date 2025/9/3 17:53
 */
@Mapper(componentModel = "spring")
public interface NowNewsConverter extends ConsumerConverter<NowNewsApiReq, NowNewsReq, NowNewsApiRes, NowNewsRes> {

    @Override
    default NowNewsApiReq convertReq(NowNewsReq request) {
        NowNewsApiReq nowNewsApiReq = new NowNewsApiReq();
        if (request == null) {
            return nowNewsApiReq;
        }
        BeanUtil.copyProperties(request, nowNewsApiReq);
        return nowNewsApiReq;
    }


    //@Override
    //default NowNewsRes convertRes(NowNewsApiRes response) {
    //    NowNewsRes nowNewsRes = new NowNewsRes();
    //    if (response == null) {
    //        return nowNewsRes;
    //    }
    //
    //    List<NowNewsDto> newsList = response.getData();
    //    nowNewsRes.setData(newsList);
    //    nowNewsRes.setNewsId("");
    //    return nowNewsRes;
    //}

    @Override
    default NowNewsRes convertRes(NowNewsApiRes response, NowNewsReq request) {
        NowNewsRes nowNewsRes = new NowNewsRes();
        if (response == null) {
            return nowNewsRes;
        }

        List<NowNewsDto> newsList = response.getData();
        nowNewsRes.setData(newsList);
        nowNewsRes.setNewsId(request.getNewsId());
        return nowNewsRes;
    }
}
